package com.hiray.demos.glue

import androidx.databinding.BindingAdapter
import androidx.annotation.StringRes
import android.widget.ImageView

import com.bumptech.glide.Glide
import com.bumptech.glide.request.RequestOptions

/**
 * Created by hiray on 2018/5/31.
 *
 * @author hiray
 */
object BindingAdapterEx {

    @JvmStatic
    @BindingAdapter("imageUrl")
    fun loadImage(view: ImageView, url: String) {
        Glide.with(view.context)
                .applyDefaultRequestOptions(RequestOptions())
                .load(url)
                .into(view)
    }

    @JvmStatic
    @BindingAdapter("imageUrl")
    fun loadImageWithStringRes(view: ImageView, @StringRes urlRes: Int) {
        Glide.with(view.context)
                .applyDefaultRequestOptions(RequestOptions())
                .load(view.context.getString(urlRes))
                .into(view)
    }
}
